﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Housing;
using System.Data.SqlClient;

public partial class StreetCenter_PublishApply : System.Web.UI.Page
{
    Apply apply = new Apply();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request["id"]!=null)
        {
            string totleincome = "0";
            string avgincome = "0";
            string avgmonthincome = "0";
            string totlepro = "0";
            SqlDataReader dr = apply.GetApplyForCheckByNoid(Request.QueryString["id"].ToString());
            if (dr.Read())
            {
                txbapplynum.Text = dr["apply_peoplenum"].ToString();
                txbcheckednum.Text=dr["c"].ToString();
                txbtotlearea.Text=dr["apply_totlearea"].ToString();
                txbavgarea.Text=dr["apply_avgarea"].ToString();
                avgincome = dr["apply_avgincome"].ToString();
                totleincome = dr["apply_yearincome"].ToString();
                lblnoid.Text = dr["apply_noid"].ToString();
                avgmonthincome = Convert.ToString(int.Parse(totleincome)/12);
                totlepro = dr["apply_totleproperty"].ToString();
            }
            dr.Close();
            string pro = "";
            Property property = new Property();
            property.GetPropertyByProNoid(lblnoid.Text);
            if (property!=null)
            {
                if (property.pro_securitie!=0)
                    pro = "存款、股票、基金本金和国库券及有价证券&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;共：" + property.pro_securitie.ToString() + "元<br/>";
                if (property.pro_estat != 0)
                    pro += @"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;房产（包括产房、店面房），汽车等财产
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;共：" + property.pro_estat.ToString() + "元<br/>";
                if (property.pro_device != 0)
                    pro += @"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;生产设备等固定资产&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;共：" + property.pro_device.ToString() + "元<br/>";
                if (property.pro_other != 0)
                    pro += @"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;其他较高价值财产&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;共：" + property.pro_other.ToString() + "元";
            }
            if (totlepro != "0")
                pro += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style='color:red'>合计：" + totlepro+"</span>";
            if(pro!="")
                lblpro.Text=pro;
            else
                lblpro.Text = "没有相关财产信息！";
            Documents document = new Documents();
            string doctype = document.GetDocTypeByNoid(lblnoid.Text);
            if (ckblowest.Text == doctype)
                ckblowest.Checked = true;
            else if (ckblowincom.Text == doctype)
            {
                ckblowincom.Checked = true;
                txblowtotle.Text = totleincome;
                txblowaverage.Text = avgincome;
            }
            else if (ckbother.Text == doctype)
            {
                ckbother.Checked = true;
                txbothertotle.Text = totleincome;
                txbotheraverage.Text = avgmonthincome;
            }
            else
                return;
        }
    }
    protected void btnpublish_Click(object sender, EventArgs e)
    {
        if (txbdate.Text == "")
        {
            WebHelper.AlertAndRefresh("请选择公布起始日期");
            return;
        }
        if (ckbisconflict.Checked == false && ckbnoneconflict.Checked == false)
        {
            WebHelper.AlertAndRefresh("必须勾选公布结果");
            return;
        }
        //将公布内容添加到表内
        string ispro = "0";
        if (ckbisconflict.Checked == true && ckbnoneconflict.Checked == false)
            ispro = txbisconflict.Text;
        StreetCheck streetcheck = new StreetCheck();
        int succAddStreetCheck=streetcheck.AddStreetPublishCheck(lblnoid.Text, txbdate.Text, ispro);
        if (succAddStreetCheck>0)
        {
            if (apply.SetCheckStateAddOne(lblnoid.Text))
                WebHelper.AlertAndCloseThenRefreshLastPage("公布成功！");
            else
                WebHelper.Alert("公布失败，请重新操作");
        }
        else
            WebHelper.Alert("已公布或公布失败");
    }
}
